define([
        'app/utils/WeixinUtils',
        'text!app/tpl/pc_tubeupload.html',
        'app/service/LoginService',
        'app/service/LectureService',
        'app/directive/PptUploadDirective'
        
        ], function (
        WeixinUtils,
        pc_pptuploadTpl,
        LoginService,
        LectureService,
        PptUploadDirective
    ) {

    

    var controller = function () {

        //0. Weixin Disabled
        WeixinUtils.disableAll();

        
        LoginService.checkLoginEncryValid($.getHashUrlParam("encry"), function(resp){

            //1. Data Initialized
            if(resp.status!="200"){
                //无效的encry，给个提示框，然后返回到登录页面
                $.alert(resp.result, function(){

                    $.redirectTo($.wjtBaseFront + "/pc_tube_login");
                });
            }
            
            $.fn.cookie('unionid', resp.result);


            var unionid = $.fn.cookie('unionid');


            LectureService.listAppLectureByUnionid(unionid, function(resp){

                console.log(resp);

                //2. Weixin Initialized
                WeixinUtils.disableAll();


                //3. tpl Initialized - Never change!!!
                var tpl = WebUtils.tplInitialized();

                //4. UI Initialized
                var pc_pptuploadUI = _.template(pc_pptuploadTpl)({
                    "lectures": resp.result
                });
               

                //4. Assemble
                tpl.append(pc_pptuploadUI);

                //5. Render - Never change!!!
                WebUtils.render(tpl);


                //6. Directive initialized
                PptUploadDirective.directive_logout();
                PptUploadDirective.directive_tubeupload();                

            })


        })

      


        //7. routechange - Never change!!!
        controller.onRouteChange = WebUtils.routeChange;

    };

    return controller;


});
